//
//  DetailView.m
//  DongChiDaChiProject1
//
//  Created by lanou3g on 15/10/29.
//  Copyright © 2015年 com.lanou3g. All rights reserved.
//

#import "DetailView.h"

@implementation DetailView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self addView];
    }
    return self;
}

// 添加视图
- (void)addView
{
    // scrollview
    self.backgroudScrollView = [[UIScrollView alloc] initWithFrame:self.frame];
    self.backgroudScrollView.backgroundColor = [UIColor whiteColor];
    self.backgroudScrollView.contentSize = CGSizeMake(kScreenWidth, 1.2 * kScreenHeight);
    [self addSubview:_backgroudScrollView];
    
    // 大图片
    self.bigPictureImage = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, 250 * kWidthFitParameter)];
   // self.bigPictureImage.backgroundColor = [UIColor magentaColor];
    [self.backgroudScrollView addSubview:_bigPictureImage];
    
    // 心型button
    self.xinXingButton = [UIButton buttonWithType:UIButtonTypeSystem];
    self.xinXingButton.frame = CGRectMake(300 * kWidthFitParameter, 180 * kWidthFitParameter, 50 * kWidthFitParameter, 50 * kWidthFitParameter);
    [self.xinXingButton setBackgroundImage:[UIImage imageNamed:@"8058b57f365d77c7a52f1e12ca38c482.jpg"] forState:UIControlStateNormal];
    self.xinXingButton.layer.cornerRadius = 50 * kWidthFitParameter / 2;
    self.xinXingButton.layer.masksToBounds = YES;
    self.xinXingButton.backgroundColor = [UIColor cyanColor];
    [self.backgroudScrollView addSubview:_xinXingButton];
    
    // 99+
    self.shuZiLabel = [[UILabel alloc] initWithFrame:CGRectMake(335 * kWidthFitParameter, 205 * kWidthFitParameter, 25 * kWidthFitParameter, 25 * kWidthFitParameter)];
    self.shuZiLabel.backgroundColor = [UIColor orangeColor];
    self.shuZiLabel.layer.cornerRadius = 30 * kWidthFitParameter / 2;
    self.shuZiLabel.layer.masksToBounds = YES;
    self.shuZiLabel.text = @"999+";
    self.shuZiLabel.font = [UIFont systemFontOfSize:9 * kWidthFitParameter ];
    [self.backgroudScrollView addSubview:_shuZiLabel];
    
    // 标题
    self.titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(15 * kWidthFitParameter, self.bigPictureImage.bottom + 15 * kWidthFitParameter, 150 * kWidthFitParameter, 40 * kWidthFitParameter)];
   // self.titleLabel.backgroundColor = [UIColor cyanColor];
    [self.backgroudScrollView addSubview:_titleLabel];
    
    // 小图片
    self.smallPictureImage = [[UIImageView alloc] initWithFrame:CGRectMake(self.titleLabel.left, self.titleLabel.bottom + 10 * kWidthFitParameter, 70 * kWidthFitParameter, 70 * kWidthFitParameter)];
  //  self.smallPictureImage.backgroundColor = [UIColor cyanColor];
    self.smallPictureImage.layer.cornerRadius = 70 * kWidthFitParameter / 2;
    [self.backgroudScrollView addSubview:_smallPictureImage];
    
    // 效果
    self.effectLabel = [[UILabel alloc] initWithFrame:CGRectMake(self.smallPictureImage.right + 15 * kWidthFitParameter, self.smallPictureImage.top, 250 * kWidthFitParameter, 25 * kWidthFitParameter)];
    self.effectLabel.font = [UIFont systemFontOfSize:13 * kWidthFitParameter];
  //  self.effectLabel.backgroundColor = [UIColor cyanColor];
    [self.backgroudScrollView addSubview:_effectLabel];
    
    // 使用人群
    self.shiYongRenQunLabel = [[UILabel alloc] initWithFrame:CGRectMake(self.effectLabel.left, self.effectLabel.bottom + 5 * kWidthFitParameter, 250 * kWidthFitParameter, 25 * kWidthFitParameter)];
    self.shiYongRenQunLabel.font = [UIFont systemFontOfSize:13 * kWidthFitParameter];
   // self.shiYongRenQunLabel.backgroundColor = [UIColor cyanColor];
    [self.backgroudScrollView addSubview:_shiYongRenQunLabel];
    
    // 食材
    self.shiCaiLabel = [[UILabel alloc] initWithFrame:CGRectMake(50 * kWidthFitParameter, self.smallPictureImage.bottom + 30 * kWidthFitParameter, 80 * kWidthFitParameter, 35 * kWidthFitParameter)];
    self.shiCaiLabel.text = @"食材";
    self.shiCaiLabel.font = [UIFont systemFontOfSize:25 * kWidthFitParameter];
    self.shiCaiLabel.textColor = [UIColor colorWithHue:1 saturation:0.5 brightness:0.5 alpha:1];
   // self.shiCaiLabel.backgroundColor = [UIColor whiteColor];
    [self.backgroudScrollView addSubview:_shiCaiLabel];
    // 原料
    self.yuanLiaoTabel = [[UITableView alloc] initWithFrame:CGRectMake(self.smallPictureImage.left, self.shiCaiLabel.bottom + 15 * kWidthFitParameter, 200 * kWidthFitParameter, 20 * kWidthFitParameter)];
   
   // self.yuanLiaoLabel.backgroundColor = [UIColor cyanColor];
    [self.backgroudScrollView addSubview:_yuanLiaoTabel];
    
    // 营养
    self.yingYangLabel = [[UILabel alloc] initWithFrame:CGRectMake(self.smallPictureImage.left, self.yuanLiaoLabel.bottom + 20 * kWidthFitParameter, (375 - 40) * kWidthFitParameter, 100 * kWidthFitParameter)];
    self.yingYangLabel.font = [UIFont systemFontOfSize:15 * kWidthFitParameter];
   // self.yingYangLabel.backgroundColor = [UIColor cyanColor];
    self.yingYangLabel.numberOfLines = 0;
    [self.backgroudScrollView addSubview:_yingYangLabel];
    
    
    
    
    
}

// 根据食材和营养改变scrollview的大小
- (void)changeFrameOfScrollViewWithShiCai:(NSInteger)shicaiCount yingYang:(NSString *)yingYangString
{
    // 改变原料的大小
    // 建立一个字典
    
//    NSDictionary *shiCaiDic = [NSDictionary dictionaryWithObject:[UIFont systemFontOfSize:15] forKey:NSFontAttributeName];
//    CGRect frame = [shiCaiString boundingRectWithSize:CGSizeMake(200 * kWidthFitParameter, 10000) options:NSStringDrawingUsesLineFragmentOrigin attributes: shiCaiDic context:nil];
//    CGRect newFrame = self.yuanLiaoLabel.frame;
//    newFrame.size.height = frame.size.height;
//    self.yuanLiaoLabel.frame = newFrame;
//    self.yuanLiaoLabel.height = self.yuanLiaoLabel.height + 40;
//    // 改变营养的大小
    self.yuanLiaoTabel.frame = CGRectMake(self.yuanLiaoTabel.left, self.yuanLiaoTabel.top, self.yuanLiaoTabel.width, 44 * kWidthFitParameter * shicaiCount);
    
    
//    // 先改变营养的frame
    self.yingYangLabel.top = self.yuanLiaoTabel.bottom + 20 * kWidthFitParameter;
//    // 建立一个字典
    NSDictionary *yingYangDic = [NSDictionary dictionaryWithObject:[UIFont systemFontOfSize:15 * kWidthFitParameter] forKey:NSFontAttributeName];
    CGRect yingYangFrame = [yingYangString boundingRectWithSize:CGSizeMake(self.yingYangLabel.width, 10000) options:NSStringDrawingUsesLineFragmentOrigin attributes:yingYangDic context:nil];
    CGRect yingYangNewFrame = self.yingYangLabel.frame;
    yingYangNewFrame.size.height = yingYangFrame.size.height;
    self.yingYangLabel.frame = yingYangNewFrame;
    
    // 改变scrollview的大小
    self.backgroudScrollView.contentSize = CGSizeMake(kScreenWidth, self.yingYangLabel.bottom + 100 * kWidthFitParameter);
//    CGRect scrollViewFrame = self.backgroudScrollView.frame;
//    scrollViewFrame.size.height = self.yingYangLabel.bottom + 100 * kWidthFitParameter;
//    self.backgroudScrollView.frame = scrollViewFrame;
    
    
    
}




@end
